<?php

/*

Bank (bank.php)

*/

$rank_check = 1;
$page_title = "Bank";
include "header.inc.php";

mysql_query("DELETE FROM bank_interest2 WHERE day != '$datestamp' AND game = '$game'");
$get_account_info = fetch("SELECT * FROM bank2 WHERE user = '$userid' AND game = '$game'");

	// Start Check

	$checking = "bank";
	$limit = $datestamp;

	$findCheck = fetch("SELECT * FROM checking2 WHERE userid = '$userid' AND check_what = '$checking' AND timestamp = '$limit' AND game = '$game'");

	if (!$findCheck[id])
	{
		$dailyInterest = round(($get_account_info[points] * ($get_account_info[rate]-1)) / 365);
		$newpoints = round($get_account_info[points] + $dailyInterest);
		mysql_query("UPDATE bank2 SET points=$newpoints WHERE user = '$userid' AND game = '$game'");
		mysql_query("INSERT INTO bank_interest2 (user,day,game) VALUES ('$userid','$datestamp','$game')");
		$get_account_info = fetch("SELECT * FROM bank2 WHERE user = '$userid' AND game = '$game'");
		$interestLine = "<p align=center><font color=red><b>Your $dailyInterest $pointsVar daily interest has been 		collected and added to your bank account!</b></font></p>";

		mysql_query("DELETE FROM checking2 WHERE userid = '$userid' AND check_what = '$checking' AND game = '$game'");
		mysql_query("INSERT INTO checking2 (userid,check_what,timestamp,game) VALUES ('$userid','$checking','$limit','$game')");
	}

	// End Check


if (!$get_account_info[user])
{
	echo "$openHTML<p align=center><b>The Bank</b></p><p>Welcome to the Bank. You don't have an account yet. Would you like to open one?</p><p><a href=$base_url/open_account.pro.php?game=$game>Open Bank Account</a></p>$closeHTML";
}
else
{
	$interestRate = ($get_account_info[rate]-1)*100;
	$yearlyInterest = round(($get_account_info[points] * ($get_account_info[rate]-1)));
	$dailyInterest = round($yearlyInterest / 365);

	echo "$openHTML$interestLine";

	$findPage = fetch("SELECT * FROM game_pages WHERE page_title = '$page_title' AND game = '$game'");
	if (!$findPage[id])
	{
		print "<P><B>The Bank</B></P>

<P>Hello $username, welcome to the bank. I am the bank
teller here. Here you can keep your money safe. Also you can earn
interest on the balance left in the bank! You should visit here every
day to collect the intest you have earned the previous day!!</P>";
	}
	else
	{
		include "showpage.inc.php";
		print "$findPage[page_info]";
	}

ECHO <<<END

<P><FORM ACTION="bank_transaction.pro.php?game=$game" METHOD=POST>
   <CENTER><TABLE CELLSPACING=6 CELLPADDING=0 WIDTH=500 height=90>
      <TR BGCOLOR="$reallyLight">
         <TD WIDTH=175>
	<p><font size=-1>
	<b>Balance:</b> $get_account_info[points]<br>
	<b>Interest rate:</b> $interestRate%<br>
	<b>Yearly Interest:</b> $yearlyInterest $pointsVar<br>
	<b>Daily Interest:</b> $dailyInterest $pointsVar</font>
	</p>
         </TD>
         <TD>
            <P align=center><FONT SIZE="-1">I would like to:<br>
            <INPUT TYPE=radio NAME=mult VALUE="-1"> Withdraw --
            <INPUT TYPE=radio NAME=mult VALUE=1> Deposit<BR>
            <INPUT TYPE=text NAME=amount VALUE="" SIZE=12>
            <INPUT TYPE=submit NAME=Submit VALUE="Complete Transaction"></FONT></P>
         </TD>
      </TR>
   </TABLE>
   </CENTER>
</FORM></P>

<p align=center><b>Remember to come back every day to collect your interest :)</b></p>
$closeHTML

END;

}

?>
